home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / MPW Interfaces & Libraries / CIncludes / Sound.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-29  |  14.0 KB  |  511 lines  |  [TEXT/MPS ]

  1.  
  2. /************************************************************
  3.  
  4. Created: Monday, December 2, 1991 at 5:07 PM
  5.  Sound.h
  6.  C Interface to the Macintosh Libraries
  7.  
  8.  
  9.   Copyright Apple Computer, Inc. 1986-1991
  10.   All rights reserved
  11.  
  12. ************************************************************/
  13.  
  14.  
  15. #ifndef __SOUND__
  16. #define __SOUND__
  17.  
  18. #ifndef __TYPES__
  19. #include <Types.h>
  20. #endif
  21.  
  22. #ifndef __FILES__
  23. #include <Files.h>
  24. #endif
  25.  
  26.  
  27. enum {
  28.  
  29.  swMode = -1,                                /* Sound Driver modes */
  30.  ftMode = 1,
  31.  ffMode = 0,
  32.  
  33.  
  34. #define synthCodeRsrc 'snth'                /* Resource types used by Sound Manager */
  35. #define soundListRsrc 'snd '
  36.  
  37. #define twelfthRootTwo 1.05946309434
  38.  
  39.  rate22khz = 0x56EE8BA3,                    /* 22254.54545 in fixed-point */
  40.  rate11khz = 0x2B7745D1,                    /* 11127.27273 in fixed-point */
  41.  
  42. /* synthesizer numbers for SndNewChannel */
  43.  squareWaveSynth = 1,                        /*square wave synthesizer*/
  44.  waveTableSynth = 3,                        /*wave table synthesizer*/
  45.  sampledSynth = 5,                            /*sampled sound synthesizer*/
  46.  
  47. /* old Sound Manager MACE synthesizer numbers */
  48.  MACE3snthID = 11,
  49.  MACE6snthID = 13,
  50.  
  51. /* command numbers for SndDoCommand and SndDoImmediate */
  52.  nullCmd = 0,
  53.  initCmd = 1,
  54.  freeCmd = 2,
  55.  quietCmd = 3,
  56.  flushCmd = 4,
  57.  reInitCmd = 5,
  58.  
  59.  waitCmd = 10,
  60.  pauseCmd = 11,
  61.  resumeCmd = 12,
  62.  callBackCmd = 13
  63. };
  64. enum {
  65.  syncCmd = 14,
  66.  emptyCmd = 15,
  67.  
  68.  tickleCmd = 20,
  69.  requestNextCmd = 21,
  70.  howOftenCmd = 22,
  71.  wakeUpCmd = 23,
  72.  availableCmd = 24,
  73.  versionCmd = 25,
  74.  totalLoadCmd = 26,
  75.  loadCmd = 27,
  76.  
  77.  scaleCmd = 30,
  78.  tempoCmd = 31,
  79.  
  80.  freqDurationCmd = 40,
  81.  restCmd = 41,
  82.  freqCmd = 42,
  83.  ampCmd = 43,
  84.  timbreCmd = 44,
  85.  getAmpCmd = 45,
  86.  
  87.  waveTableCmd = 60,
  88.  phaseCmd = 61
  89. };
  90. enum {
  91.  
  92.  soundCmd = 80,
  93.  bufferCmd = 81,
  94.  rateCmd = 82,
  95.  continueCmd = 83,
  96.  doubleBufferCmd = 84,
  97.  getRateCmd = 85,
  98.  
  99.  sizeCmd = 90,
  100.  convertCmd = 91,
  101.  
  102.  stdQLength = 128,
  103.  dataOffsetFlag = 0x8000,
  104.  
  105.  waveInitChannelMask = 0x07,
  106.  waveInitChannel0 = 0x04,
  107.  waveInitChannel1 = 0x05,
  108.  waveInitChannel2 = 0x06,
  109.  waveInitChannel3 = 0x07,
  110.  
  111. /* channel initialization parameters */
  112.  initPanMask = 0x0003,                        /* mask for right/left pan values */
  113.  initSRateMask = 0x0030,                    /* mask for sample rate values */
  114.  initStereoMask = 0x00C0,                    /* mask for mono/stereo values */
  115.  initCompMask = 0xFF00,                        /* mask for compression IDs */
  116.  
  117.  initChanLeft = 0x0002                        /* left stereo channel */
  118. };
  119. enum {
  120.  initChanRight = 0x0003,                    /* right stereo channel */
  121.  initNoInterp = 0x0004,                        /* no linear interpolation */
  122.  initNoDrop = 0x0008,                        /* no drop-sample conversion */
  123.  initMono = 0x0080,                            /* monophonic channel */
  124.  initStereo = 0x00C0,                        /* stereo channel */
  125.  initMACE3 = 0x0300,                        /* MACE 3:1 */
  126.  initMACE6 = 0x0400,                        /* MACE 6:1 */
  127.  
  128.  initChan0 = 0x0004,                        /* channel 0 - wave table only */
  129.  initChan1 = 0x0005,                        /* channel 1 - wave table only */
  130.  initChan2 = 0x0006,                        /* channel 2 - wave table only */
  131.  initChan3 = 0x0007,                        /* channel 3 - wave table only */
  132.  
  133.  stdSH = 0x00,                                /* Standard sound header encode value */
  134.  extSH = 0xFF,                                /* Extended sound header encode value */
  135.  cmpSH = 0xFE,                                /* Compressed sound header encode value */
  136.  
  137.  notCompressed = 0,                            /* compression ID's */
  138.  twoToOne = 1,
  139.  eightToThree = 2,
  140.  threeToOne = 3,
  141.  sixToOne = 4,
  142.  
  143.  outsideCmpSH = 0                            /* MACE constants */
  144. };
  145. enum {
  146.  insideCmpSH = 1,
  147.  aceSuccess = 0,
  148.  aceMemFull = 1,
  149.  aceNilBlock = 2,
  150.  aceBadComp = 3,
  151.  aceBadEncode = 4,
  152.  aceBadDest = 5,
  153.  aceBadCmd = 6,
  154.  sixToOnePacketSize = 8,
  155.  threeToOnePacketSize = 16,
  156.  stateBlockSize = 64,
  157.  leftOverBlockSize = 32,
  158.  
  159.  firstSoundFormat = 0x0001,                    /* general sound format */
  160.  secondSoundFormat = 0x0002,                /* special sampled sound format (HyperCard) */
  161.  
  162.  dbBufferReady = 0x00000001,                /* double buffer is filled */
  163.  dbLastBuffer = 0x00000004,                    /* last double buffer to play */
  164.  
  165.  sysBeepDisable = 0x0000,                    /* SysBeep() enable flags */
  166.  sysBeepEnable = 0x0001,
  167.  
  168.  unitTypeNoSelection = 0xFFFF,                /* unitTypes for AudioSelection.unitType */
  169.  unitTypeSeconds = 0x0000
  170. };
  171.  
  172.  
  173. /*   Structures for Sound Driver   */
  174.  
  175.  
  176. typedef unsigned char FreeWave[30001];
  177.  
  178. struct FFSynthRec {
  179.  short mode;
  180.  Fixed count;
  181.  FreeWave waveBytes;
  182. };
  183.  
  184. typedef struct FFSynthRec FFSynthRec;
  185. typedef FFSynthRec *FFSynthPtr;
  186.  
  187. struct Tone {
  188.  short count;
  189.  short amplitude;
  190.  short duration;
  191. };
  192.  
  193. typedef struct Tone Tone;
  194.  
  195.  
  196. typedef Tone Tones[5001];
  197.  
  198. struct SWSynthRec {
  199.  short mode;
  200.  Tones triplets;
  201. };
  202.  
  203. typedef struct SWSynthRec SWSynthRec;
  204. typedef SWSynthRec *SWSynthPtr;
  205.  
  206.  
  207. typedef unsigned char Wave[256];
  208. typedef Wave *WavePtr;
  209.  
  210. struct FTSoundRec {
  211.  short duration;
  212.  Fixed sound1Rate;
  213.  long sound1Phase;
  214.  Fixed sound2Rate;
  215.  long sound2Phase;
  216.  Fixed sound3Rate;
  217.  long sound3Phase;
  218.  Fixed sound4Rate;
  219.  long sound4Phase;
  220.  WavePtr sound1Wave;
  221.  WavePtr sound2Wave;
  222.  WavePtr sound3Wave;
  223.  WavePtr sound4Wave;
  224. };
  225.  
  226. typedef struct FTSoundRec FTSoundRec;
  227. typedef FTSoundRec *FTSndRecPtr;
  228.  
  229. struct FTSynthRec {
  230.  short mode;
  231.  FTSndRecPtr sndRec;
  232. };
  233.  
  234. typedef struct FTSynthRec FTSynthRec;
  235. typedef FTSynthRec *FTSynthPtr;
  236.  
  237.  
  238. typedef pascal void (*SndCompletionProcPtr)(void);
  239.  
  240. /*   Structures for Sound Manager   */
  241.  
  242. struct SndCommand {
  243.  unsigned short cmd;
  244.  short param1;
  245.  long param2;
  246. };
  247.  
  248. typedef struct SndCommand SndCommand;
  249.  
  250.  
  251. typedef long Time;                            /* in half milliseconds */
  252.  
  253.  
  254.  
  255. typedef struct SndChannel SndChannel;
  256. typedef SndChannel *SndChannelPtr;
  257.  
  258.  
  259. typedef pascal void (*SndCallBackProcPtr)(SndChannelPtr chan, SndCommand cmd);
  260.  
  261. struct SndChannel {
  262.     struct SndChannel *nextChan;
  263.     Ptr firstMod;                              /* reserved for the Sound Manager */
  264.     SndCallBackProcPtr callBack;
  265.     long userInfo;
  266.     Time wait;                                 /* The following is for internal Sound Manager use only.*/
  267.     SndCommand cmdInProgress;
  268.     short flags;
  269.     short qLength;
  270.     short qHead;                               /* next spot to read or -1 if empty */
  271.     short qTail;                               /* next spot to write = qHead if full */
  272.     SndCommand queue[stdQLength];
  273. };
  274.  
  275. /* MACE structures */
  276. struct StateBlock {
  277.  short stateVar[stateBlockSize];
  278. };
  279.  
  280. typedef struct StateBlock StateBlock;
  281. typedef StateBlock *StateBlockPtr;
  282.  
  283. struct LeftOverBlock {
  284.  unsigned long count;
  285.  char sampleArea[leftOverBlockSize];
  286. };
  287.  
  288. typedef struct LeftOverBlock LeftOverBlock;
  289. typedef LeftOverBlock *LeftOverBlockPtr;
  290.  
  291. struct ModRef {
  292.  unsigned short modNumber;
  293.  long modInit;
  294. };
  295.  
  296. typedef struct ModRef ModRef;
  297.  
  298. struct SndListResource {
  299.  short format;
  300.  short numModifiers;
  301.  ModRef modifierPart[1];                    /*This is a variable length array*/
  302.  short numCommands;
  303.  SndCommand commandPart[1];                    /*This is a variable length array*/
  304.  char dataPart[1];                            /*This is a variable length array*/
  305. };
  306.  
  307. typedef struct SndListResource SndListResource;
  308. typedef SndListResource *SndListPtr;
  309.  
  310. struct SoundHeader {
  311.  Ptr samplePtr;                                /* if NIL then samples are in sampleArea */
  312.  unsigned long length;                        /* length of sound in bytes */
  313.  Fixed sampleRate;                            /* sample rate for this sound */
  314.  unsigned long loopStart;                    /* start of looping portion */
  315.  unsigned long loopEnd;                        /* end of looping portion */
  316.  unsigned char encode;                        /* header encoding */
  317.  unsigned char baseFrequency;                /* baseFrequency value */
  318.  char sampleArea[1];
  319. };
  320.  
  321. typedef struct SoundHeader SoundHeader;
  322. typedef SoundHeader *SoundHeaderPtr;
  323.  
  324. struct CmpSoundHeader {
  325.  Ptr samplePtr;                                /* if nil then samples are in sample area */
  326.  unsigned long numChannels;                    /* number of channels i.e. mono = 1 */
  327.  Fixed sampleRate;                            /* sample rate in Apples Fixed point representation */
  328.  unsigned long loopStart;                    /* loopStart of sound before compression */
  329.  unsigned long loopEnd;                        /* loopEnd of sound before compression */
  330.  unsigned char encode;                        /* data structure used , stdSH, extSH, or cmpSH */
  331.  unsigned char baseFrequency;                /* same meaning as regular SoundHeader */
  332.  unsigned long numFrames;                    /* length in frames ( packetFrames or sampleFrames ) */
  333.  extended80 AIFFSampleRate;                    /* IEEE sample rate */
  334.  Ptr markerChunk;                            /* sync track */
  335.  Ptr futureUse1;                            /* reserved by Apple */
  336.  Ptr futureUse2;                            /* reserved by Apple */
  337.  StateBlockPtr stateVars;                    /* pointer to State Block */
  338.  LeftOverBlockPtr leftOverSamples;            /* used to save truncated samples between compression calls */
  339.  unsigned short compressionID;                /* 0 means no compression, non zero means compressionID */
  340.  unsigned short packetSize;                    /* number of bits in compressed sample packet */
  341.  unsigned short snthID;                        /* resource ID of Sound Manager snth that contains NRT C/E */
  342.  unsigned short sampleSize;                    /* number of bits in non-compressed sample */
  343.  char sampleArea[1];                        /* space for when samples follow directly */
  344. };
  345.  
  346. typedef struct CmpSoundHeader CmpSoundHeader;
  347. typedef CmpSoundHeader *CmpSoundHeaderPtr;
  348.  
  349. struct ExtSoundHeader {
  350.  Ptr samplePtr;                                /* if nil then samples are in sample area */
  351.  unsigned long numChannels;                    /* number of channels,  ie mono = 1 */
  352.  Fixed sampleRate;                            /* sample rate in Apples Fixed point representation */
  353.  unsigned long loopStart;                    /* same meaning as regular SoundHeader */
  354.  unsigned long loopEnd;                        /* same meaning as regular SoundHeader */
  355.  unsigned char encode;                        /* data structure used , stdSH, extSH, or cmpSH */
  356.  unsigned char baseFrequency;                /* same meaning as regular SoundHeader */
  357.  unsigned long numFrames;                    /* length in total number of frames */
  358.  extended80 AIFFSampleRate;                    /* IEEE sample rate */
  359.  Ptr markerChunk;                            /* sync track */
  360.  Ptr instrumentChunks;                        /* AIFF instrument chunks */
  361.  Ptr AESRecording;
  362.  unsigned short sampleSize;                    /* number of bits in sample */
  363.  unsigned short futureUse1;                    /* reserved by Apple */
  364.  unsigned long futureUse2;                    /* reserved by Apple */
  365.  unsigned long futureUse3;                    /* reserved by Apple */
  366.  unsigned long futureUse4;                    /* reserved by Apple */
  367.  char sampleArea[1];                        /* space for when samples follow directly */
  368. };
  369.  
  370. typedef struct ExtSoundHeader ExtSoundHeader;
  371. typedef ExtSoundHeader *ExtSoundHeaderPtr;
  372.  
  373. struct ConversionBlock {
  374.  short destination;
  375.  short unused;
  376.  CmpSoundHeaderPtr inputPtr;
  377.  CmpSoundHeaderPtr outputPtr;
  378. };
  379.  
  380. typedef struct ConversionBlock ConversionBlock;
  381. typedef ConversionBlock *ConversionBlockPtr;
  382.  
  383. struct SMStatus {
  384.  short smMaxCPULoad;
  385.  short smNumChannels;
  386.  short smCurCPULoad;
  387. };
  388.  
  389. typedef struct SMStatus SMStatus;
  390. typedef SMStatus *SMStatusPtr;
  391.  
  392. struct SCStatus {
  393.  Fixed scStartTime;
  394.  Fixed scEndTime;
  395.  Fixed scCurrentTime;
  396.  Boolean scChannelBusy;
  397.  Boolean scChannelDisposed;
  398.  Boolean scChannelPaused;
  399.  Boolean scUnused;
  400.  unsigned long scChannelAttributes;
  401.  long scCPULoad;
  402. };
  403.  
  404. typedef struct SCStatus SCStatus;
  405. typedef SCStatus *SCStatusPtr;
  406.  
  407. struct AudioSelection {
  408.  long unitType;
  409.  Fixed selStart;
  410.  Fixed selEnd;
  411. };
  412.  
  413. typedef struct AudioSelection AudioSelection;
  414. typedef AudioSelection *AudioSelectionPtr;
  415.  
  416. struct SndDoubleBuffer {
  417.  long dbNumFrames;
  418.  long dbFlags;
  419.  long dbUserInfo[2];
  420.  char dbSoundData[1];
  421. };
  422.  
  423. typedef struct SndDoubleBuffer SndDoubleBuffer;
  424. typedef SndDoubleBuffer *SndDoubleBufferPtr;
  425.  
  426.  
  427. typedef pascal void (*SndDoubleBackProcPtr) (SndChannelPtr channel,
  428.            SndDoubleBufferPtr doubleBufferPtr);
  429.  
  430. struct SndDoubleBufferHeader {
  431.  short dbhNumChannels;
  432.  short dbhSampleSize;
  433.  short dbhCompressionID;
  434.  short dbhPacketSize;
  435.  Fixed dbhSampleRate;
  436.  SndDoubleBufferPtr dbhBufferPtr[2];
  437.  SndDoubleBackProcPtr dbhDoubleBack;
  438. };
  439.  
  440. typedef struct SndDoubleBufferHeader SndDoubleBufferHeader;
  441. typedef SndDoubleBufferHeader *SndDoubleBufferHeaderPtr;
  442.  
  443.  
  444. #ifdef __cplusplus
  445. extern "C" {
  446. #endif
  447. pascal OSErr SndDoCommand(SndChannelPtr chan,const SndCommand *cmd,Boolean noWait)
  448.  = 0xA803; 
  449. pascal OSErr SndDoImmediate(SndChannelPtr chan,const SndCommand *cmd)
  450.  = 0xA804; 
  451. pascal OSErr SndNewChannel(SndChannelPtr *chan,short synth,long init,SndCallBackProcPtr userRoutine)
  452.  = 0xA807; 
  453. pascal OSErr SndDisposeChannel(SndChannelPtr chan,Boolean quietNow)
  454.  = 0xA801; 
  455. pascal OSErr SndPlay(SndChannelPtr chan,Handle sndHdl,Boolean async)
  456.  = 0xA805; 
  457. pascal OSErr SndAddModifier(SndChannelPtr chan,ProcPtr modifier,short id,
  458.  long init)
  459.  = 0xA802; 
  460. pascal OSErr SndControl(short id,SndCommand *cmd)
  461.  = 0xA806; 
  462.  
  463. pascal void SetSoundVol(short level); 
  464. #pragma parameter GetSoundVol(__A0)
  465. pascal void GetSoundVol(short *level)
  466.  = {0x4218,0x10B8,0x0260}; 
  467. pascal void StartSound(const void *synthRec,long numBytes,SndCompletionProcPtr completionRtn); 
  468. pascal void StopSound(void); 
  469. pascal Boolean SoundDone(void); 
  470.  
  471. pascal NumVersion SndSoundManagerVersion(void)
  472.  = {0x203C,0x000C,0x0008,0xA800}; 
  473. pascal OSErr SndStartFilePlay(SndChannelPtr chan,short fRefNum,short resNum,
  474.  long bufferSize,void *theBuffer,AudioSelectionPtr theSelection,ProcPtr theCompletion,
  475.  Boolean async)
  476.  = {0x203C,0x0D00,0x0008,0xA800}; 
  477. pascal OSErr SndPauseFilePlay(SndChannelPtr chan)
  478.  = {0x203C,0x0204,0x0008,0xA800}; 
  479. pascal OSErr SndStopFilePlay(SndChannelPtr chan,Boolean async)
  480.  = {0x203C,0x0308,0x0008,0xA800}; 
  481. pascal OSErr SndChannelStatus(SndChannelPtr chan,short theLength,SCStatusPtr theStatus)
  482.  = {0x203C,0x0010,0x0008,0xA800}; 
  483. pascal OSErr SndManagerStatus(short theLength,SMStatusPtr theStatus)
  484.  = {0x203C,0x0014,0x0008,0xA800}; 
  485. pascal void SndGetSysBeepState(short *sysBeepState)
  486.  = {0x203C,0x0018,0x0008,0xA800}; 
  487. pascal OSErr SndSetSysBeepState(short sysBeepState)
  488.  = {0x203C,0x001C,0x0008,0xA800}; 
  489. pascal OSErr SndPlayDoubleBuffer(SndChannelPtr chan,SndDoubleBufferHeaderPtr theParams)
  490.  = {0x203C,0x0020,0x0008,0xA800}; 
  491.  
  492. pascal NumVersion MACEVersion(void)
  493.  = {0x203C,0x0000,0x0010,0xA800}; 
  494. pascal void Comp3to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  495.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  496.  = {0x203C,0x0004,0x0010,0xA800}; 
  497. pascal void Exp1to3(const void *inBuffer,void *outBuffer,unsigned long cnt,
  498.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  499.  = {0x203C,0x0008,0x0010,0xA800}; 
  500. pascal void Comp6to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  501.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  502.  = {0x203C,0x000C,0x0010,0xA800}; 
  503. pascal void Exp1to6(const void *inBuffer,void *outBuffer,unsigned long cnt,
  504.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  505.  = {0x203C,0x0010,0x0010,0xA800}; 
  506. #ifdef __cplusplus
  507. }
  508. #endif
  509.  
  510. #endif
  511.